<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *员工管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'礼品列表'),
	array('op'=>'edit','title'=>'添加礼品'),	
);
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'rid'=>intval($_RQ['id']));
	$this->session('rid',intval($_RQ['id']));
	$rid=$this->session('rid');
	$list=pdo_getall('jy_ailiao_liping',$params,$fields,'','id desc');
	$return['list']=$list;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','edit'=>false,'delall'=>false,'del_op'=>'del','list'=>array(
			array('name'=>'title','title'=>'礼品名称','type'=>'string'),
			array('name'=>'price','title'=>'消耗金币','type'=>'string'),
			array('name'=>'picurl','title'=>'礼品图标','type'=>'image'),
			array('name'=>'jifen','title'=>'点赞数','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'switch','set'=>'set'),
		),'action' => 
		    array (
			      array('type'=>'href','op'=>'edit','title'=>'编辑'),
		),)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_ailiao_liping',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'礼品列表'),
		),
		'edit'=>array(
			array('name'=>'title','title'=>'礼品名称','type'=>'string'),
			array('name'=>'picurl','title'=>'礼品图标','type'=>'image'),
			array('name'=>'price','title'=>'消耗金币','type'=>'unitstring','unit'=>'个'),
			array('name'=>'jifen','title'=>'点赞数','type'=>'unitstring','unit'=>'个','help'=>'收礼方获得点赞数'),
		)
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
		'title'=>trim($postdata['title']),
		'picurl'=>trim($postdata['picurl']),
		'price'=>$postdata['price'],
		'jifen'=>intval($postdata['jifen']),
	);
	$id=intval($postdata['id']);
	if($id){
		pdo_update('jy_ailiao_liping',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['createtime']=time();
		pdo_insert('jy_ailiao_liping',$data);
		$id=pdo_insertid();
	}
	exi('操作成功！','','goback');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_ailiao_liping',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
if($_RQ['op']=='set'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择要编辑的活动！','error');
	}
	$post=get_postdata();
	if(isset($post['status'])){
		pdo_update('jy_ailiao_liping',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}
	exi('操作成功！');
}